//
//  ImageUploaderVC.swift
//  swift_review
//
//  Created by Andrew on 2024/11/26.
//

import UIKit

class ImageUploaderVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .white
    }
    
    func singlePhoto() {
        let uploader = ImageUploader()
        let imageData = UIImage(named: "example")!.jpegData(compressionQuality: 0.8)!
        let fileName = "example.jpg"

        uploader.uploadSingleImage(urlString: "https://example.com/upload", image: imageData, fileName: fileName) { result in
            switch result {
            case .success(let data):
                print("上传成功: \(String(data: data, encoding: .utf8) ?? "无返回值")")
            case .failure(let error):
                print("上传失败: \(error.localizedDescription)")
            }
        }
    }
    
    func morePhonts() {
        let uploader = ImageUploader()
        let image1 = UIImage(named: "example1")!.jpegData(compressionQuality: 0.8)!
        let image2 = UIImage(named: "example2")!.jpegData(compressionQuality: 0.8)!
        let images = [image1, image2]
        let fileNames = ["example1.jpg", "example2.jpg"]

        uploader.uploadMultipleImages(urlString: "https://example.com/upload", images: images, fileNames: fileNames) { result in
            switch result {
            case .success(let data):
                print("上传成功: \(String(data: data, encoding: .utf8) ?? "无返回值")")
            case .failure(let error):
                print("上传失败: \(error.localizedDescription)")
            }
        }
    }
}
